<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->

<head>
<meta charset="utf-8">
<title>新建报盘</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description">
<meta content="" name="author">
<link href="${request.getContextPath()}/Public/assets/admin/css/css.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/font-awesome/css/font-awesome.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/simple-line-icons/simple-line-icons.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/css/bootstrap.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/uniform/css/uniform.default.css"
	rel="stylesheet" type="text/css">

<link
	href="${request.getContextPath()}/Public/assets/global/css/components-rounded.css"
	id="style_components" rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/css/plugins.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/layout.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/themes/default.css"
	rel="stylesheet" type="text/css" id="style_color">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/custom.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/common.css"
	rel="stylesheet" type="text/css">



<link rel="shortcut icon"
	href="${request.getContextPath()}/Public/favicon.ico">
<!--[if lt IE 9]>
<script src="${request.getContextPath()}/Public/assets/global/plugins/respond.min.js"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/excanvas.min.js"></script>
<![endif]-->
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery-migrate.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery-ui.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/js/bootstrap.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery.blockui.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery.cokie.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/uniform/jquery.uniform.min.js"
	type="text/javascript"></script>

<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery.sparkline.min.js"
	type="text/javascript"></script>

<script
	src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"
	type="text/javascript"></script>

<script
	src="${request.getContextPath()}/Public/assets/global/scripts/metronic.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/admin/scripts/layout.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/admin/scripts/indexComponent.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/admin/scripts/commonUtils.js"
	type="text/javascript"></script>

<!-- select2控件 -->
<!-- select2控件 -->
<script type="text/javascript"
	src="${request.getContextPath()}/Public/assets/global/plugins/select2/select2.js"></script>
<script type="text/javascript"
	src="${request.getContextPath()}/Public/assets/global/plugins/select2/select2_locale_zh-CN.js"></script>
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/select2/select2.css"
	rel="stylesheet" type="text/css">

<!-- 数据验证 -->
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery-validation/js/jquery.validate.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery-validation/js/localization/messages_zh.js"
	type="text/javascript"></script>
<!-- 数字小数点后两位工具类 -->
<script type="text/javascript" src="${request.getContextPath()}/Public/js/common/util.js"></script>
<style type="text/css">
* {
	font-size: 14px;
}

#buyfrom label.error {
	color: Red;
	font-size: 13px;
	margin-left: 5px;
	padding-left: 16px;
	background: left no-repeat;
}

.commonBtn {
	margin: 0 5px;
}

.normalBtn {
	border: 1px solid #C0C1B4;
	color: #555;
	background-color: #fff;
}

.ttLbl .radio {
	padding-top: 0;
}
</style>

</head>
<body class="page-header-top-fixed">
	<div class="page-header">
		<!--头部开始-->
		<#include "/include/top.html" />
		<!-- 头部信息结束 -->

		<!-- 头部菜单开始 -->
		<#include "/include/top_menu.html" />
		<!-- 头部菜单结束 -->
	</div>
	<!-- END HEADER -->
	<div class="page-container">
		<div class="page-content">
			<div class="container-fluid">
				<ul class="page-breadcrumb breadcrumb">
					<li><a href="#">首页</a><i class="fa fa-circle"></i></li>
					<li class="active">撮合管理<i class="fa fa-circle"></i>
					</li>
					<li class="active">撮合交易管理</li>
					<li class="active">新建报盘</li>
				</ul>
				<div class="row margin-top-10">
					<div class="col-md-12">
						<div class="portlet light bordered" align="center">
							<form class="form-horizontal" id="poolfrom">
								<input type="hidden" in="only" name="only" value="${only}">
								<div class="form-group">
									<p align="left">
									<h3 style="font-weight: bold;">新建报盘</h3>
									</p>
									<div style="clear: both;"></div>
									<br> <label class="col-sm-2 control-label ">企业名称：</label>
									<div class="col-sm-1">
										<input class="form-control" width="100" id="companyid"
											name="customerId" style="width: 270px; height: 60px;" />
									</div>
									
									 <input type="hidden" id="companyName" value=""> 
								</div>
								
								<!-- 新增报价人    2016年1月4日下午1:28:21 -->
								<div class="form-group">
									<label class="col-sm-2 control-label">报价人：</label>
									<div class="col-sm-1">
										<input class="form-control" width="100" id="offerer"
											name="offerer" value="${user.id}" style="width: 130px; height: 60px;" />
									</div>
								</div>
									
								
								<div class="form-group">
									<label class="col-sm-2 control-label">采购类型：</label>
									<div class="col-sm-1">
										<label class="ttLbl"><input type="radio"
											class="form-control" name="poolType" value="2"> 采购</label>
									</div>
									<div class="col-sm-1">
										<label class="ttLbl"><input type="radio"
											class="form-control" name="poolType" checked="checked"
											value="1"> 销售</label>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">产品：</label>
									<div class="col-sm-2">
										<select class="form-control" id="prodId" name="prodId">
											<#list prodList as pro>
											<option value="${(pro.id)!}" class="${(pro.id)}">${(pro.name)!}
											</option> </#list>
										</select>
									</div>
								</div>
								<#list itemAttrList as itemAttr>
								<div class="form-group">
									<input type="hidden" name="arrtName" value="${itemAttr.name}">
									<input type="hidden" name="fillmode"
										value="${itemAttr.fillmode}"> <input type="hidden"
										name="ids" value="${itemAttr.id?c}"> <label
										class="col-sm-2 control-label">${itemAttr.name}：</label> <#if 
										itemAttr.name ='品牌'>
									<div class="col-sm-1">
										<#else>
										<div class="col-sm-2">
											</#if>
											<!-- 填写方式  文本框 -->
											<#if itemAttr.fillmode?? && itemAttr.fillmode==0> <input
												class="required" type="text" name="attrValue${itemAttr.id}"
												class="form-control" /> </#if>
											<!-- 填写方式  下拉框-->
											<#if itemAttr.fillmode?? && itemAttr.fillmode==1> <select
												name="attrValue${itemAttr.id}" class="form-control">
												<#if itemAttr.mainproperty?? && itemAttr.mainproperty==0 >
												<option value="">---请选择---</option> </#if> <#if
												itemAttr.optionsValue??> <#list itemAttr.optionsValue as
												optionsValue>
												<option value="${optionsValue!''}">${optionsValue!''}</option>
												</#list> </#if>
												<select> </#if> <#if itemAttr.fillmode?? &&
													itemAttr.fillmode==2> <#if itemAttr.optionsValue??> <#list
													itemAttr.optionsValue as optionsValue>
													<input type="checkbox" name="attrValue${itemAttr.id}"
													value="${optionsValue}" class="md-radiobtn"
													class="form-control" /> ${optionsValue} </#list> </#if>
													</#if>
													<!-- 填写方式  单选框--> <#if itemAttr.fillmode?? &&
													itemAttr.fillmode==3>
													<select class="form-control required"<#if
														itemAttr.name ='品牌'>id="mainBrandSel"</#if>
														name="attrValue${itemAttr.id}"> <#if
														itemAttr.mainproperty?? && itemAttr.mainproperty==0 >
														<option value="">---请选择---</option> </#if> <#if
														itemAttr.optionsValue??> <#list itemAttr.optionsValue as
														optionsValue>
														<option value="${optionsValue!''}">${optionsValue!''}</option>
														</#list> </#if>
														<select> </#if> 
										</div>
										<#if itemAttr.name == "品牌">
										<div id="addBrandDiv" style="display: none;">
											<!-- <input type="button" value="+" id="addBrandBtn"
												style="float: left;" /> -->
											<img  id="addBrandBtn" src="${request.getContextPath()}/Public/assets/admin/img/add.png" style="float: left; cursor:pointer;" />
										</div>
										</#if>
									</div>
									</#list>


									<div class="form-group">
										<!-- 交易指导价 -->
										<input type="hidden" id="high" value="${itemPrice.high!''}">
										<input type="hidden" id="low"  value="${itemPrice.low!''}">
										
										<label class="col-sm-2 control-label">数量：</label>
										<div class="col-sm-2">
											<input type="text" class="form-control" id="quantit"
												name="quantit">
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-2 control-label">价格：</label>
										<div class="col-sm-1" >
											<select name="priceType" id="priceType" class="form-control" onchange="bao(this.options[this.options.selectedIndex].value)">
												<option value="0" >实价</option>
												<!-- 铜 银 锌是只能是升贴水的  2015年12月30日上午10:19:29  负数就保存负数  -->
												<option value="1" <#if itemId == 26276 || itemId == 26280 || itemId == 26288 > selected="selected"</#if> >升贴水</option>
												<!--<option value="2">贴</option> -->
											</select>
										</div>
										<div style="width: 200px; float: left;">
											<input type="text" id="price" name="price" class="form-control"/>
											
												<!-- 价格校验暂时舍弃  2015年12月29日下午4:46:57 -->
												<!-- <input type="text" id="price" name="price" class="form-control" onblur="checkPrice()"/> -->
												<!-- <span id="ERROR1" style="display:none;color: red;font-size: 12px;"">实价不能高于最高报盘价</span>
								        		<span id="ERROR2" style="display:none;color: red;font-size: 12px;"">实价不能低于最低报盘价</span> -->
										</div>
										<div style="display: none;" id="qihuoyue">
											<label class="col-sm-2 control-label">期货月：</label>
											<div style="width: 200px; float: left;">
												<select class="form-control" id="futuresMonth"
													name="futuresMonth"> <#list futuresMonthList as
													futuresM >
													<option value="${futuresM!}"<#if futuresM?? &&
														futuresMonth?? && futuresM==futuresMonth
														></#if>>${futuresM!}</option> </#list>
												</select>
											</div>
										</div>
										
									</div>
									<!--  <div class="form-group">
									<label class="col-sm-2 control-label">单位：</label>
									<div class="col-sm-2">
										<select id="unit" name="unit" class="form-control">
											<option value="0" selected="selected">吨</option>
											<option value="1">千克</option>
										</select>
									</div>
								</div>-->
									<div class="form-group">
										<label class="col-sm-2 control-label">仓库：</label>
										<div class="col-sm-1">
											<select class="form-control" id="area"
												onchange="selWareName()" name="area" > <#list
												arealist as area >
												<option value="${area.id}">${area.name}</option> </#list>
											</select>

										</div>
										<div id="idWare" class="col-sm-2">
											<!-- <select class="form-control" id="wareId" name="wareId">
											</select> -->
											<input class="form-control wareId" id="wareId" name="wareId">
										</div>
										<div id="addWareHouseDiv" style="display: none;">
											<!-- <input type="button" value="+" id="addWareHouseBtn"
												style="float: left;" /> -->
												<img  id="addWareHouseBtn" src="${request.getContextPath()}/Public/assets/admin/img/add.png" style="float: left; cursor:pointer;" />
										</div>


									</div>
									<input type="hidden" id="wareName" name="wareName"> <input
										type="hidden" id="pingpai" name="pingpai"> <input
										type="hidden" id="cangkuId" name="cangkuId"> <input
										type="hidden" id="cangkuName" name="cangkuName">
									<div class="form-group">
										<div class="col-sm-offset-2 col-sm-10">
											<button id="Button" onclick="javascript :history.back(-1);"
												type="button" class="btn green pull-left">
												返回 <i class="m-icon-swapright m-icon-white"></i>
											</button>

											<button type="button" id="savetButton"
												class="btn green pull-left">
												新建<i class="m-icon-swapright m-icon-white"></i>
											</button>
										</div>
									</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- 底部开始 -->
	<#include "/include/foot.html" />
	<!-- 底部结束 -->
</body>
<script>
jQuery(document).ready(function() {

	//价格类型选择 实体 不现实期货月  选择升贴水 显示期货月 qihuoyue
	if($("#priceType").val() == 0){
		$("#qihuoyue").css("display","none");
	}else{
		$("#qihuoyue").css("display","inline");
	}
	
	$(".control-label").css("text-align", "center");

	$("#companyid").select2({
		language : "zh_CN",
		placeholder : "关键字搜索公司",//文本框的提示信息
		minimumInputLength : 0,//至少输入n个字符，才去加载数据
		allowClear : true, //是否允许用户清除文本信息
		/* multiple:true,//多选属性 */
		ajax : { // instead of writing the function to execute the request we use Select2's convenient helper
			url : "${request.getContextPath()}/dealMake/queryCompanyByNm.do",
			dataType : 'json',//接收的数据类型
			type : "post",
			data : function(term, page) {//在查询时向服务器端传输的数据
				return {
					companyName : term, //联动查询的字符
					page : 10
				//一次性加载的数据条数
				};
			},
			results : function(data, page) { // parse the results into the format expected by Select2.
				// since we are using custom formatting functions we do not need to alter remote JSON data
				var realNames = new Array();
				for (var i = 0; i < data.length; i++) {
					realNames.push({
						id : data[i].id,
						text : data[i].name
					});
				}
				return {
					results : realNames
				};
			}
		},
		formatResult : resultFormatResult, // omitted for brevity, see the source of this page
		formatSelection : resultFormatSelection_1, // omitted for brevity, see the source of this page
		dropdownCssClass : "bigdrop", // apply css that makes the dropdown taller
		escapeMarkup : function(m) {
			return m;
		} // we do not want to escape markup since we are displaying html in results
	});

	toSelect2();
	
	Metronic.init(); // init metronic core componets
	Layout.init(); // init layout 
	selWareName();
	
	$("input[name='poolType']")
			.click(
					function() {
						if ($(this).val() == 2) {
							$("#addBrandDiv").css(
									"display", "block");
							$("#addWareHouseDiv").css(
									"display", "block");
						} else {

							extraBrandCount = 0;
							extraWareHouseCount = 0;
							$("#addBrandDiv").css(
									"display", "none");
							$("#addWareHouseDiv").css(
									"display", "none");
							$(
									"select[name='extraBrandSel']")
									.each(
											function(index,
													element) {
												$(element)
														.parent(
																"div")
														.remove();
											});
							$(
									"input[name='extraWareHouseSel']")
									.each(
											function(index,
													element) {
												$(element)
														.parent(
																"div")
														.remove();
											});
						}
					});

	$("#addBrandBtn").click(function() {
		if (extraBrandCount >= 2) {
			return;
		}
		var brandHtml = '<div class="col-sm-1"><select class="form-control required" name="extraBrandSel" id="brandSel'
				+ (extraBrandCount++)
				+ '">';
		$(this)
				.before(
						brandHtml
								+ $(
										"#mainBrandSel")
										.html()
								+ "</select></div");
	});

	//仓库动态加进去 
	$("#addWareHouseBtn").click(function() {
		//alert(extraWareHouseCount);
		if (extraWareHouseCount >= 2) {
			return;
		}
		extraWareHouseCount++;
		var wareHouseHtml = '<div class="col-sm-2"><input class="form-control wareId" name="extraWareHouseSel" id="wareHouseSel'+ extraWareHouseCount+'">';
		$(this).before(wareHouseHtml+ $("#wareId").html()+ "</div");
		choseWareHouseBlur("#wareHouseSel"+extraWareHouseCount);
	});
	
	//小数点后两位check
	checkNum_2($('#price'));
	checkNum5($('#quantit'));
});
	var extraBrandCount = 0;
	var extraWareHouseCount = 0;
	recordDate();
	//初始化日期
	function recordDate() {
		var nowDate = new Date();
		//$('#date-picker').attr("date-date",nowDate.getFullYear()+"/"+parseInt(nowDate.getMonth()+1)+"/"+nowDate.getDate());
		$('.date-picker').datepicker({
			autoclose : true
		});

	}

	function selWareName() {
		//$("#wareId").empty();
		var value = $("#area").val();
		if (value == -1) {
			var ops = document.getElementById("wareId").options;
			ops.length = 0;
			ops.add(new Option("请选择仓库", ""));
			return;
		}
		
		
		choseWareHouse(value);
		
		/* $.ajax({
			url : "${request.getContextPath()}/dealMake/selWarehouseByArea.do",
			type : "post",
			dataType : "json",
			async : false,
			data : {
				"areaId" : value
			},
			success : function(data) {
				var jsonData = eval(data);//接收到的数据转化为JQuery对象，由JQuery为我们处理 
				$("#wareId").append("<option value=''>--请选择--</option>");
				$.each(jsonData, function(index, item) {
					$("#wareId").append(
							"<option value='"+item.id+"'>" + item.name
									+ "</option>");
				});
			}
		}); */

		/* $("input[name='extraWareHouseSel']").each(function(index, element) {
			$(element).parent("div").remove();
		}); */
	}
	function resultFormatResult(medata) {
		return medata.text;
	}

	function resultFormatSelection(medata) {
		return medata.text;
	}

	function resultFormatSelection_1(medata) {
		$("#companyName").val(medata.text);
        return medata.text; 
	}
	
	function quit() {

		window.location.href = "${request.getContextPath()}/buypool/buylist.do";

	}
	var id = 1;

	function addware() {
		var sel = $("#idWare").html();
		var str = "<div id='idWare"+id+"' class='col-sm-2'>" + sel + "</div>"
		alert(str);
		$("#idWare" + id - 1 + "").append(str);
		//id.removeAttr("Id");
		id = id + 1;
	}
	function commodity(prodId, prodName, obj) {
		$("#prodId").val(prodId);
		$("#prodName").val(prodName);

		var prodclasss = document.getElementsByName("prodclass");
		$("input[name='prodclass']").removeClass("green");

		$(obj).addClass("green");
	}

	$("#savetButton").bind("click",
		function() {
			var pingpai = "";
			$("select[name='extraBrandSel']").each(
					function(index, element) {
						if (pingpai != '' && pingpai != null) {
							pingpai += ","
						}
						pingpai += $(element).val();
					});
			$("#pingpai").val(pingpai);

			var cangkuId = "";
			var cangkuName = "";
			$("input[name='extraWareHouseSel']").each(
					function(index, element) {
						if (cangkuId != '' && cangkuId != null) {
							cangkuId += ",";
							cangkuName += ","
						}
						cangkuId += $(element).val();
						cangkuName += $(element).find(
								"option:selected").text();
					});
			$("#cangkuId").val(cangkuId);
			$("#cangkuName").val(cangkuName);

			var wareName = $("#wareId").find("option:selected")
					.text();
			var companyid = $("#companyid").val();
			var prodId = Number($("#prodId").val()).toFixed(2);
			var quantit = Number($("#quantit").val()).toFixed(4);
			var price = $("#price").val();
			var wareId = $("#wareId").val();
			var offerer = $("#offerer").val();
			var poolType = $("input[name='poolType']:checked").val();
			
			//品牌 
			var mainBrandSel = $("#mainBrandSel").val();
			var brandSel0 = $("#brandSel0").val();
			var brandSel1 = $("#brandSel1").val();
			
			if(brandSel0 != undefined){
				if(mainBrandSel == brandSel0){
					alert("不能选择一样的品牌，请重新选择！");
					return;
				}
			}
			
			
			if(brandSel0 != undefined && brandSel1 != undefined){
				if(mainBrandSel == brandSel0){
					alert("不能选择一样的品牌，请重新选择！");
					return;
				}
				if(mainBrandSel == brandSel1){
					alert("不能选择一样的品牌，请重新选择！");
					return;
				}
				if(brandSel0 == brandSel1){
					alert("不能选择一样的品牌，请重新选择！");		
					return;
				}
			}
			
			
			if (companyid == null || companyid == '') {
				alert("请选择企业名称");
				return;
			}
			
			if (offerer == null || offerer == '') {
				alert("请选择报价员 ");
				return;
			}
			if (poolType == null || poolType == '') {
				alert("请选择采购类型");
				return;
			}

			if (prodId == null || prodId == '') {
				alert("请选择采购产品");
				return;
			}
			if (wareId == null || wareId == '') {
				alert("请选择仓库");
				return;
			}

			if (!quantit || quantit <= 0) {
				alert("数量必须大于0");
				return;
			}
			price
			if(price == null || price == ''){
				alert("请填写价格");
				return;
			}
			
			var priceType = $("#priceType").val()
			if (priceType == 1 || priceType == 2) {
				var futuresMonth = $("#futuresMonth").val();
				if (futuresMonth == null || futuresMonth == '') {
					alert("价格类型为升贴水时,期货月不能为空！");
					return;
				}
			}
			
			//价格校验暂时舍弃  2015年12月29日下午4:46:00
			/* //实价校验
			if($("#ERROR1").css("display") == "inline"){
				return false;
			}
			if($("#ERROR2").css("display") == "inline"){
				return false;
			}
			 */
			$("#wareName").val(wareName);
			$.ajax({
				url : "${request.getContextPath()}/PoolManage/addPool.do",
				type : "post",
				dataType : "json",
				async : false,
				data : $("#poolfrom").serialize(),
				success : function(result) {
					if (result.code == "success") {
						alert(result.message);
						window.location.href = "${request.getContextPath()}/business/index.do";
					} else if (result.code == "error") {
						alert(result.message);
						window.location.href = "${request.getContextPath()}/business/index.do";
					} else if (result.code == "CFKH") {
						alert("商品不存在");
						window.location.href = "${request.getContextPath()}/business/index.do";
					} else {
						alert(result);
						window.location.href = "${request.getContextPath()}/business/index.do";
					}
				}
			});
		});

	$("#futuresMonth1").datepicker({
		language : "zh-CN",
		autoclose : true,//选中之后自动隐藏日期选择框
		clearBtn : true,//清除按钮
		todayBtn : true,//今日按钮
		format : "yymm",//日期格式
	//startDate:new Date()
	});

	recordDate();
	//初始化日期
	function recordDate() {
		var nowDate = new Date();
		//$('#date-picker').attr("date-date",nowDate.getFullYear()+"/"+parseInt(nowDate.getMontd()+1)+"/"+nowDate.getDate());
		$('.date-picker').datepicker({
			autoclose : true
		});
	}
	
	
	//实价与交易指导价进行对比 
	function checkPrice(){
		//数字强转为int类型 
		var price = parseFloat($("#price").val());
		//最高价
		var high = parseFloat($("#high").val());
		//最低价
		var low = parseFloat($("#low").val());
		//alert(price+"-------"+high);
		if($("#priceType").val() == 0){
			if(price > high){
				$("#ERROR2").css("display","none");
				$("#ERROR1").css("display","inline");
			}else if(price < low){
				$("#ERROR1").css("display","none");
				$("#ERROR2").css("display","inline");
			}else{
				$("#ERROR1").css("display","none");
				$("#ERROR2").css("display","none");
			}	
		}
		if($("#priceType").val() == 1){
				$("#ERROR1").css("display","none");
				$("#ERROR2").css("display","none");
		}
		if($("#priceType").val() == 2){
				$("#ERROR1").css("display","none");
				$("#ERROR2").css("display","none");
		}
	}
	
	//select onchange事件
	 function bao(priceType){
		$("#price").val("");
	 	if(priceType == 0){
			if(price > high){
				$("#ERROR2").css("display","none");
				$("#ERROR1").css("display","inline");
			}else if(price < low){
				$("#ERROR1").css("display","none");
				$("#ERROR2").css("display","inline");
			}else{
				$("#ERROR1").css("display","none");
				$("#ERROR2").css("display","none");
			}	
		}
		if($("#priceType").val() == 1){
				$("#ERROR1").css("display","none");
				$("#ERROR2").css("display","none");
		}
		if($("#priceType").val() == 2){
				$("#ERROR1").css("display","none");
				$("#ERROR2").css("display","none");
		}
		
		//价格类型选择 实体 不现实期货月  选择升贴水 显示期货月 qihuoyue
		if(priceType == 0){
			$("#qihuoyue").css("display","none");
		}else{
			$("#qihuoyue").css("display","inline");
		}
	} 
	
	
	function choseWareHouse(value){
		//仓库模糊搜索
		$("#wareId").select2({// 
			   language: "zh_CN",
		       placeholder: "搜索仓库",//文本框的提示信息
		       minimumInputLength: 0,//至少输入n个字符，才去加载数据
		       allowClear: true, //是否允许用户清除文本信息
		       ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
		    	   url : "${request.getContextPath()}/dealMake/selWarehouseByAreaBlur.do",
		           dataType: 'json',//接收的数据类型
		           type : "post",
		           data: function (term, page) {//在查询时向服务器端传输的数据
		               return {
		            	   wareName:term, //联动查询的字符
		            	   areaId : value,
		            	   companyName:$("#companyName").val(),
		                   page: 10 //一次性加载的数据条数
		               };
		           },
		           results: function (data, page) { // parse the results into the format expected by Select2.
		               // since we are using custom formatting functions we do not need to alter remote JSON data
		               var realNames = new Array();    
		                    for (var i = 0; i < data.length; i++) {
		                         realNames.push({id: data[i].id, text: data[i].name});
		                         
		                  }
		               return {results: realNames};
		           }
		       	},
		       	formatResult: resultFormatResult, // omitted for brevity, see the source of this page
		       	formatSelection: resultFormatSelection,  // omitted for brevity, see the source of this page
		       	dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
		       	escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
	    });
		
	}
	
	function choseWareHouseBlur(obj){
		//仓库模糊搜索
		
		$(obj).select2({// 
			   language: "zh_CN",
		       placeholder: "搜索仓库",//文本框的提示信息
		       minimumInputLength: 0,//至少输入n个字符，才去加载数据
		       allowClear: true, //是否允许用户清除文本信息
		       ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
		    	   url : "${request.getContextPath()}/dealMake/selWarehouseByAreaBlur.do",
		           dataType: 'json',//接收的数据类型
		           type : "post",
		           data: function (term, page) {//在查询时向服务器端传输的数据
		               return {
		            	   wareName:term, //联动查询的字符
		            	   areaId : $("#area").val(),
		                   page: 10 //一次性加载的数据条数
		               };
		           },
		           results: function (data, page) { // parse the results into the format expected by Select2.
		               // since we are using custom formatting functions we do not need to alter remote JSON data\
		               var realNames = new Array();    
		                    for (var i = 0; i < data.length; i++) {
		                         realNames.push({id: data[i].id, text: data[i].name});
		                         
		                  }
		               return {results: realNames};
		           }
		       	},
		       	formatResult: resultFormatResult, // omitted for brevity, see the source of this page
		       	formatSelection: resultFormatSelection,  // omitted for brevity, see the source of this page
		       	dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
		       	escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
	    });
		
	}
	
	function toSelect2(){
		$("#offerer").select2({
			 language: "zh_CN",
		       placeholder: "搜索报价员",//文本框的提示信息
		       minimumInputLength: 0,//至少输入n个字符，才去加载数据
		       allowClear: true ,//是否允许用户清除文本信息
		       ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
		    	   url : "${request.getContextPath()}/business/offererList.do",
		           dataType: 'json',//接收的数据类型
		           type : "post",
		           data: function (term, page) {//在查询时向服务器端传输的数据
		               return {
		            	   userName:term, //联动查询的字符
		                   page: 10 //一次性加载的数据条数
		               };
		           },
		           results: function (data, page) { // parse the results into the format expected by Select2.
		               // since we are using custom formatting functions we do not need to alter remote JSON data\
		               var realNames = new Array();    
		                    for (var i = 0; i < data.length; i++) {
		                         realNames.push({id: data[i].id, text: data[i].name});
		                         
		                  }
		               return {results: realNames};
		           }
		       	},
		        initSelection: function(element, callback) {//加载初始化
					var userId = $("#offerer").val();
					if (userId !== "") {
						$.ajax("${request.getContextPath()}/business/initOfferer.do").done(function(data) { 
							callback({id:data.id,text:data.name}); 
						});
					}
				},
		       	formatResult: resultFormatResult, // omitted for brevity, see the source of this page
		       	formatSelection: resultFormatSelection,  // omitted for brevity, see the source of this page
		       	dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
		       	escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
		});
	}
	
</script>
</html>

